﻿Public Class FormProduct

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        FormProductEditor.ShowDialog()
    End Sub

    Private Sub FormProduct_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        UI.FormatDataGrid(dgv)
        LoadData()
    End Sub

    Private Sub txtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.TextChanged
        LoadData()
    End Sub

    Public Sub LoadData()
        Cmd.Parameters("@S") = Me.txtSearch.Text
        Me.dgv.DataSource = Cmd.ExecuteDataTable("SELECT * FROM Product WHERE Active=1 AND ProductCode+ProductName LIKE '%'+@S+'%'")

    End Sub

    Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click

        If Me.dgv.SelectedRows.Count = 0 Then
            Exit Sub
        End If

        Dim row = Me.dgv.SelectedRows(0)
        Dim frm As New FormProductEditor()
        frm.txtProductId.Text = row.Cells("ProductId").Value
        frm.txtProductCode.Text = row.Cells("ProductCode").Value
        frm.txtProductName.Text = row.Cells("ProductName").Value
        frm.ShowDialog()

    End Sub

    Private Sub txt1_TextChanged(sender As Object, e As EventArgs) Handles txt1.TextChanged
        Dim test As Date
        If Date.TryParseExact(txt1.Text.ToString(), "yyyy/mm/dd", _
                              System.Globalization.CultureInfo.CurrentCulture, _
                              Globalization.DateTimeStyles.None, test) Then
            MessageBox.Show("Ok")

        Else

        End If

    End Sub

    Private Sub dgv_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgv.CellContentClick

    End Sub
End Class